class User {
  final String id;
  final String email;
  final String name;
  final String? bio;
  final String? phone;
  final String? location;
  final String? avatar;

  User({
    required this.id,
    required this.email,
    required this.name,
    this.bio,
    this.phone,
    this.location,
    this.avatar,
  });

  factory User.fromJson(Map<String, dynamic> json) {
    return User(
      id: json['id'] ?? json['_id'] ?? '',
      email: json['email'] ?? '',
      name: json['name'] ?? '',
      bio: json['bio'],
      phone: json['phone'],
      location: json['location'],
      avatar: json['avatar'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'email': email,
      'name': name,
      'bio': bio,
      'phone': phone,
      'location': location,
      'avatar': avatar,
    };
  }

  // 创建用户副本
  User copyWith({
    String? id,
    String? email,
    String? name,
    String? bio,
    String? phone,
    String? location,
    String? avatar,
  }) {
    return User(
      id: id ?? this.id,
      email: email ?? this.email,
      name: name ?? this.name,
      bio: bio ?? this.bio,
      phone: phone ?? this.phone,
      location: location ?? this.location,
      avatar: avatar ?? this.avatar,
    );
  }
}
